<template>
	<view class="my-home">
		<!--header-->
		<view class="tui-mybg-box"  >
			<view class="transparent"></view>
			<view class="tui-my-bg">
				<image :src="me.cover"  mode="aspectFill"></image>
			</view>
			
			<view class="tui-header-icon">
				<!-- #ifdef MP -->
				<view class="tui-set-box">
					<view class="tui-icon-box tui-icon-message" @tap="href('/pages/user/comps/notifaction')">
						<tui-icon name="message" color="#fff" :size="32"></tui-icon>
						<view class="tui-badge tui-badge-white" v-if="unread.length">{{unread.length}}</view>
					</view>
					<view class="tui-icon-box tui-icon-setup" @tap="href('/pages/user/comps/setup')">
						<tui-icon name="setup" color="#fff" :size="32" ></tui-icon>
					</view>
				</view>
				<!-- #endif -->
			</view>
			
			<view class="tui-header-center" v-if="me.name">
				<image :src="me.avatar" mode="" class="tui-avatar" @tap.stop="preview(me.avatar)"></image>
				<view class="tui-info">
					<view class="tui-nickname">{{me.name}}</view>
					<!-- <view class="tui-explain">ID: {{me.id}}</view> -->
				</view>
			</view>
		</view>
		
		<view class="action-area">
			<view class="tui-content-box">
				<view class="tui-box tui-order-box">
					<tui-list-cell :arrow="true" padding="0" :lineLeft="false">
						<view class="tui-header-btm">
							<view class="tui-btm-item" @tap.stop="href('/pages/user/comps/my?id='+me.id)">
								<view class="tui-btm-num">
									<image src="/static/images/icon/my_homepage.png" mode="aspectFill"></image>
								</view>
								<view class="tui-btm-text">我的主页</view>
							</view>
							<view class="tui-btm-item" @tap.stop="href('/pages/user/comps/follow?uid='+me.id)">
								<view class="tui-btm-num">
									<image src="/static/images/icon/my_follow.png" mode="aspectFill"></image>
								</view>
								<view class="tui-btm-text">关注</view>
							</view>
							<view class="tui-btm-item"@tap.stop="href('/pages/user/comps/followme?uid='+me.id)">
								<view class="tui-btm-num">
									<image src="/static/images/icon/my_fans.png" mode="aspectFill"></image>
								</view>
								<view class="tui-btm-text">粉丝</view>
							</view>
							<view class="tui-btm-item"  @tap.stop="signClick">
								<view class="tui-btm-num">
									<image src="/static/images/icon/my_sign.png" mode="aspectFill"></image>
								</view>
								<view class="tui-btm-text" >用户签到</view>
							</view>
						</view>
					</tui-list-cell>
			 </view>
			</view>
			
			<view class="mine">
				<tui-list-cell :arrow="true" padding="0" :lineLeft="false" @tap.stop="href('/pages/user/comps/mycircles')">
				  <view class="tui-cell-header"  >
						<view class="tui-cell-title" >
							<image src="/static/images/icon/my_circle.png" mode="aspectFill"></image>我的圈子
						</view>
						<view class="tui-cell-sub">
							<image src="/static/images/user/godetail.png" mode="aspectFill"></image>
						</view>
					</view>
				</tui-list-cell>	
				<tui-list-cell :arrow="true" padding="0" :lineLeft="false" @tap.stop="href('/pages/user/comps/posts?mid='+me.id)">
					<view class="tui-cell-header">
						<view class="tui-cell-title" >
							<image src="/static/images/icon/my_post_record.png" mode="aspectFill"></image>打卡记录
						</view>
						<view class="tui-cell-sub">
							<image src="/static/images/user/godetail.png" mode="aspectFill"></image>
						</view>
					</view>
				</tui-list-cell>
				<tui-list-cell :arrow="true" padding="0" :lineLeft="false" @tap.stop="href('/pages/user/comps/workarea?mid='+me.id)" v-if="use_share">
					<view class="tui-cell-header">
						<view class="tui-cell-title" >
							<image src="/static/images/icon/my_create.png" mode="aspectFill"></image>创作中心
						</view>
						<view class="tui-cell-sub">
							<image src="/static/images/user/godetail.png" mode="aspectFill"></image>
						</view>
					</view>
				</tui-list-cell>
				<tui-list-cell :arrow="true" padding="0" :lineLeft="false" @tap.stop="href('/pages/activity/comps/actarea?mid='+me.id)">
					<view class="tui-cell-header">
						<view class="tui-cell-title" >
							<image src="/static/images/icon/my_activity.png" mode="aspectFill"></image>活动管理
						</view>
						<view class="tui-cell-sub">
							<image src="/static/images/user/godetail.png" mode="aspectFill"></image>
						</view>
					</view>
				</tui-list-cell>
				<tui-list-cell :arrow="true" padding="0" :lineLeft="false" @tap.stop="href('/pages/user/comps/mywallet?mid='+me.id)" v-if="use_share">
					<view class="tui-cell-header">
						<view class="tui-cell-title" >
							<image src="/static/images/icon/wallet.png" mode="aspectFill"></image>我的钱包
						</view>
						<view class="tui-cell-sub">
							<image src="/static/images/user/godetail.png" mode="aspectFill"></image>
						</view>
					</view>
				</tui-list-cell>
			</view>
		</view>
		
		<!-- 签到成功 -->
		<sign-success :isShow="isShowSign" :todayReward="todayReward" :tomorrowReward="tomorrowReward"  @close="closeSign"></sign-success>
		
	</view>
</template>

<script>
	import api from '../../common/api.js'
	import Vue from 'vue'
	import signSuccess from '../../components/content/signSuccess.vue'
	export default {

		data() {
			return {
				use_share:this.use_share,							//显示作品区域
				top: 0, 		//标题图标距离顶部距离
				me:{},
				sign:{},
				unread:null,
				isShowSign:false,					//是否显示签到成功组件
				todayReward:'',						//今天签到收益
				tomorrowReward:''					//明天签到收益
			}
		},
		
		components:{
			signSuccess					//签到成功组件
		},
		
		async onShow() {
			if(!Vue.prototype.token) {
				await api.GetMe()
				this.use_video = Vue.prototype.use_video
				this.use_audio = Vue.prototype.use_audio 
				this.use_share = Vue.prototype.use_share 
			}
			await this.getMe()
			await this.getUnread()
		},
		
		onHide() {
			console.log('页面关闭');
		},
		
		methods: {
			
			async getMe() {// 获取当前登录用户信息
				let res = await api.GetMe()
				this.$store.commit('setPhone',res[0].phone)
				this.had_phone = res[0].purePhoneNumber
				this.uid = res.map(item => item.id)
				this.me = res[0]
				this.todayReward = this.me.duration_days >= 7 ? 7 : this.me.duration_days
				this.tomorrowReward = this.me.duration_days >= 7 ? 7 :	this.me.duration_days + 1
				this.flag = true //确保子组件能获取到数据
			},
			
			async getUnread() {//未读通知条数
				this.unread = await api.GetUnRead() 
				// console.log(this.unread);
			},
			
			
			preview(image){//预览图片
				let img  = []
				img.push(image)
				uni.previewImage({
					current:0,
					urls:img
				})
			},
			
			href(url) {//进行相应的页面跳转
				if (url) {
					uni.navigateTo({
						url
					})
				} else {
					this.tui.toast("功能尚未完善~")
				}
			},
			
			async signClick() {//用户签到
				
				this.signStatus = await api.SignStatus()
				// console.log(this.signStatus);
				if(this.signStatus.err == 1) {//未签到
					let sign = await api.Sign()
					if(sign.err === 0) {
						await this.getMe()
						this.isShowSign = true
					}
				}else {
					uni.showToast({
						title:'今天已签到',
						duration:600
					})
				}
			},
			
			closeSign() {//关闭签到提示
				this.isShowSign = false
			}
		},
	}
</script>

<style lang="scss">
	page {
		margin: 0;
		padding: 0;
		
	}
	.tui-header-box {
		width: 100%;
		padding: 0 30rpx 0 20rpx;
		box-sizing: border-box;
		position: fixed;
		top: 0;
		left: 0;
		display: flex;
		align-items: center;
		justify-content: flex-end;
		height: 32px;
		transform: translateZ(0);
		z-index: 1;
	}

	/* #ifndef MP */
	.tui-header-icon {
		min-width: 120rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;
	}

	/* #endif */
	/* #ifdef MP */
	.tui-set-box {
		display: flex;
		align-items: center;
		position: absolute;
		top: 15rpx;		
		right: 10rpx;
		justify-content: space-between;
	}

	/* #endif */
	.tui-icon-box {
		position: relative;
	}

	.tui-icon-setup {
		margin-left: 8rpx;
	}

	.tui-badge {
		position: absolute;
		font-size: 24rpx;
		height: 32rpx;
		min-width: 20rpx;
		padding: 0 6rpx;
		border-radius: 40rpx;
		right: 10rpx;
		top: -5rpx;
		transform: scale(0.8) translateX(60%);
		transform-origin: center center;
		display: flex;
		align-items: center;
		justify-content: center;
		z-index: 1;
	}

	.tui-badge-red {
		background: #fa4d56;
		color: #fff;
	}

	.tui-badge-white {
		background: #fff;
		color: #F74D54;
	}

	.tui-badge-dot {
		position: absolute;
		height: 12rpx;
		width: 12rpx;
		border-radius: 50%;
		right: -12rpx;
		top: 0;
		background: #F74D54;
	}
	.my-home {
		// background: #F3F3F3;
		height: 100vh;
		background: #F3F3F3;
	}
	.tui-mybg-box {
		position: relative;
		width: 100%;
		height: 410rpx;
		.transparent {
			position: absolute;
			z-index: 1;
			width: 100%;
			height: 100%;
			background:rgba(2, 2, 2, 0.25);	
			// border-bottom-left-radius:30rpx;
			// border-bottom-right-radius:30rpx;	
		}
		
	}

	.tui-my-bg {
		position: relative;
		z-index: 0;
		width: 750rpx;
		height: 410rpx;
		image {
			width: 100%;
			height: 100%;
			// border-bottom-left-radius:30rpx;
			// border-bottom-right-radius:30rpx;	
		}
	}

	.tui-header-center {
		display: flex;
		flex-direction: column;
		align-items: center;
		position: absolute;
		z-index: 1;
		width: 100%;
		height: 128rpx;
		left: 0;
		top: 95rpx;
		padding: 0 30rpx;
		box-sizing: border-box;
	}
	.tui-header-icon {
		display: flex;
		align-items: center;
		position: absolute;
		
		z-index: 1;
		width: 100%;
		top: 15rpx;
		padding: 0 30rpx;
		box-sizing: border-box;
	}

	.tui-avatar {
		flex-shrink: 0;
		width: 130rpx;
		height: 130rpx;
		display: block;
		border-radius: 65rpx;
	}

	.tui-info {
		width: 60%;
		padding: 10rpx 0;
	}

	.tui-nickname {
		font-size: 30rpx;
		font-weight: 500;
		color: #fff;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.tui-img-vip {
		width: 56rpx;
		height: 24rpx;
		margin-left: 18rpx;
	}

	.tui-explain {
		width: 80%;
		font-size: 24rpx;
		font-weight: 400;
		color: #fff;
		opacity: 0.75;
		padding-top: 8rpx;
		white-space: nowrap;
		overflow: hidden;
		text-overflow: ellipsis;
	}

	.tui-btn-edit {
		flex-shrink: 0;
		padding-right: 22rpx;
	}

	.tui-header-btm {
		width: 100%;
		padding: 30rpx 25rpx;
		box-sizing: border-box;
		// position: absolute;
		left: 0;
		top: 280rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;
		// color: #fff;
	}

	.tui-btm-item {
		flex: 1;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}

	.tui-btm-num {
		font-size: 32rpx;
		font-weight: 600;
		position: relative;
		image {
			width: 100rpx;
			height: 100rpx;
		}
	}

	.tui-btm-text {
		font-size: 24rpx;
		opacity: 0.85;
		padding-top: 4rpx;
	}
	.action-area {
		// background: #F3F3F3;
		// height: 1000rpx;
	}
	.tui-content-box {
		width: 100%;
		padding: 0 30rpx;
		box-sizing: border-box;
		position: relative;
		top: -90rpx;
		z-index: 1;
	}

	.tui-box {
		width: 100%;
		background: #fff;
		box-shadow: 0 3rpx 20rpx rgba(183, 183, 183, 0.1);
		border-radius: 18rpx;
		overflow: hidden;
	}

	.tui-order-box {
		// height: 208rpx;
	}
	.mine {
		background: #fff;
		top: -66rpx;
		position: relative;
	}
	.tui-cell-header {
		width: 100%;
		height: 100rpx;
		padding: 0 30rpx;
		box-sizing: border-box;
		display: flex;
		align-items: center;
		justify-content: space-between;
		border-top: 1rpx solid #F3F6F5;
		
	}

	.tui-cell-title {
		display: flex;
		align-items: center;
		font-size: 30rpx;
		line-height: 30rpx;
		font-weight: 600;
		color: #333;
		image {
			width: 45rpx;
			height: 45rpx;
			margin-right: 20rpx;
		}
	}

	.tui-cell-sub {
		display: flex;
		align-items: center;
		height: 74rpx;
		// width: 140rpx;
		font-size: 26rpx;
		font-weight: 400;
		color: #999;
		right: 0;
		image {
			width: 30rpx;
			height: 30rpx;
		}
	}

	.tui-order-list {
		width: 100%;
		height: 134rpx;
		padding: 0 30rpx;
		box-sizing: border-box;
		display: flex;
		align-items: center;
		justify-content: space-between;

	}

	.tui-order-item {
		flex: 1;
		display: flex;
		flex-direction: column;
		align-items: center;
	}

	.tui-order-text,
	.tui-tool-text {
		font-size: 26rpx;
		font-weight: 400;
		color: #666;
		padding-top: 4rpx;
	}

	.tui-tool-text {
		font-size: 24rpx;
	}

	.tui-order-icon {
		width: 56rpx;
		height: 56rpx;
		display: block;
	}

	.tui-assets-box {
		height: 178rpx;
		margin-top: 20rpx;
	}

	.tui-assets-list {
		height: 84rpx;
	}

	.tui-assets-num {
		font-size: 32rpx;
		font-weight: 500;
		color: #333;
		position: relative;
	}

	.tui-assets-text {
		font-size: 24rpx;
		font-weight: 400;
		color: #666;
		padding-top: 6rpx;
	}

	.tui-tool-box {
		margin-top: 20rpx;
	}

	.tui-flex-wrap {
		flex-wrap: wrap;
		height: auto;
		padding-bottom: 30rpx;
	}

	.tui-tool-item {
		width: 25%;
		display: flex;
		align-items: center;
		justify-content: center;
		flex-direction: column;
		padding-top: 30rpx;
	}

	.tui-tool-icon {
		width: 64rpx;
		height: 64rpx;
		display: block;
	}

	.tui-badge-icon {
		width: 66rpx;
		height: 30rpx;
		position: absolute;
		right: 0;
		transform: translateX(88%);
		top: -15rpx;
	}

	/*为你推荐*/
	.tui-product-list {
		display: flex;
		justify-content: space-between;
		flex-direction: row;
		flex-wrap: wrap;
		box-sizing: border-box;
	}

	.tui-product-container {
		flex: 1;
		margin-right: 2%;
	}

	.tui-product-container:last-child {
		margin-right: 0;
	}

	.tui-pro-item {
		width: 100%;
		margin-bottom: 4%;
		background: #fff;
		box-sizing: border-box;
		border-radius: 12rpx;
		overflow: hidden;
	}

	.tui-pro-img {
		width: 100%;
		display: block;
	}

	.tui-pro-content {
		display: flex;
		flex-direction: column;
		justify-content: space-between;
		box-sizing: border-box;
		padding: 20rpx;
	}

	.tui-pro-tit {
		color: #2e2e2e;
		font-size: 26rpx;
		word-break: break-all;
		overflow: hidden;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-box-orient: vertical;
		-webkit-line-clamp: 2;
	}

	.tui-pro-price {
		padding-top: 18rpx;
	}

	.tui-sale-price {
		font-size: 34rpx;
		font-weight: 500;
		color: #e41f19;
	}

	.tui-factory-price {
		font-size: 24rpx;
		color: #a0a0a0;
		text-decoration: line-through;
		padding-left: 12rpx;
	}

	.tui-pro-pay {
		padding-top: 10rpx;
		font-size: 24rpx;
		color: #656565;
	}

	.tui-btn-back {
		width: 88rpx;
		height: 88rpx;
		font-size: 26rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		border-radius: 50%;
		background-color: rgba(0, 0, 0, .5);
		color: #fff;
		position: fixed;
		bottom: 60rpx;
		right: 30rpx;
		z-index: 1;
	}
</style>
